const Menu = require('../../domain/menu/menu')
const Usecase = require('../../shared/usecase/Usecase')

class GetMenuTree extends Usecase {
  constructor({ menuRepo }) {
    super()
    this.menuRepo = menuRepo
  }
  async execute(data) {
    const menuList = await this.menuRepo.findAll(data, {}, ['name', 'code'])
    const menuTree = Menu.menuListToTree(menuList)
    return menuTree
  }
}

module.exports = GetMenuTree
